<template>
	<view class="fujin">
		
		<view class="lists" v-for="(item,index) in list">
			<view class="list">
				<view class="fa">
					<image class="icon" :src="item.avatar ? item.avatar : '../../../static/nologin.png'" mode=""></image>
					<view>{{item.nickname}}</view>
				</view>
				
				<!-- <view class="rightimg_str"  @click="goDetail('/pagesB/mine/index/fujin_list?id='+item.uid)"> -->
		
				<view class="rightimg_str">
					{{item.sd?item.sd:0}}km/h
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					{{item.time?item.time:0}}S
				</view>
				
			</view>
			
			<view class="list" :style="show_id==item.id?'padding-bottom:25rpx;border-bottom:1px solid #111823':''">
				<view class="rightimg_str"  @click="ck(item)" >
					<image style="width: 22rpx;height: 32rpx;margin-top: 10rpx;" :style="show_id==item.id?'transform-origin: 50% 50%;transform: rotate(90deg);':''"  src="/static/rightimg.png"></image>
				</view>	
				<view class="fa" style="font-size: 22rpx;">
					备注：{{item.title?item.title:"-"}}
				</view>
			</view>
			<!-- <view class="list" :style="show_id==item.id?'padding-bottom:25rpx;border-bottom:1px solid #111823':''">
				
		
			</view>
			 -->
			<view class="jilu"  style="" v-for="(items,indexs) in item.list" v-if="show_id==item.id">
				<view class="list" style="" >
					<view class="fa" style="font-size: 25rpx;">
						留言人：
						<view>{{items.nickname}}</view>
					</view>
					
					<view class="fa" style="font-size: 25rpx;float: right;margin-right: 20rpx;">
						<view>{{items.create_time}}</view>
					</view>	
					<view class="fa" v-if="uid==items.uid" @click="shanchu(items.id,indexs,index)" style="font-size: 25rpx;float: right;margin-right: 20rpx;color: red;">
						<view>删除</view>
					</view>	
				</view>
		<!-- 		<view class="list">
				
				</view> -->
				<view class="list" style="padding-bottom: 10rpx;border-bottom: 3rpx solid #111823;" >
				
					<image @click="preview(items.img)" v-if="items.img&&items.img!='../../../static/upload.png'" :src="items.img" style="width: 40px;margin-left: 40rpx;margin-bottom: 10px;" mode="widthFix"></image>
					<view class="fa" style="font-size: 25rpx;">
					
							{{items.content?items.content:"-"}}
					</view>
				</view>
			</view>
			
			<view class="list" :style="show_id==item.id?'padding-bottom:25rpx;':''">
				
				<view class=" rightimg_str1" @click="liuyan(item,index)">
					<image src="/static/com.png" style="width: 50rpx;height: 50rpx;margin-left: 40rpx;"></image>
				</view>
			<!-- 	<view class="rightimg_str"  @click="ck(item)" >
					<image style="width: 22rpx;height: 32rpx;margin-top: 10rpx;" :style="show_id==item.id?'transform-origin: 50% 50%;transform: rotate(90deg);':''"  src="/static/rightimg.png"></image>
				</view>	 -->
			</view>
			
		
		</view>
		
		
		<uni-popup ref="popup2" maskClick type="center">
			<view class="share-wrapper1">
				<view class="tp">
					
					<text v-if="lang==0">
							请输入留言内容
					</text>
				
					<text v-if="lang==1" style="font-size:16rpx;">
						Please enter the message content
					</text>
				</view>
				<view>
				
					<image class="avatar" style="width: 80rpx;height: 80rpx;margin-left: 40rpx;"  :src="img" mode="" @click="showActionSheet"></image>
				</view>
				<view class="nav_tex">
					<textarea placeholder="Enter..." :adjust-position="true" v-model="dev_name"></textarea>
				</view>
			
					<view class="bomt" @click="miaoshu()">
						
						<text v-if="lang==0">
								确定
						</text>
						<text v-if="lang==1" >
							OK
						</text>
					</view>
			
			
			</view>
		</uni-popup>
		
	<q-previewImage ref="previewImage" :urls="imgs" @onLongpress="onLongpress" @open="open" @close="close"></q-previewImage>
		
		<!-- <tabbar :current="4"></tabbar> -->
	</view>
</template>

<script>
    import Tabbar from '@/components/tabbar/tabbar.vue'
	import uniPopup from "@/components/uni-popup/uni-popup.vue";
	export default {
        components: {
            'view-tabbar': Tabbar, uniPopup
        }, 
		data() {
			return {
			
				list: [], //我的报名
				total: 0, //总条数
				page: 1, //当前页数
				nodata: false, //是否有数据
				lang:0,
				dev_name:"",
				info:[],
				show_id:0,
				img:"../../../static/upload.png",
				imgs: [],
				index:0,
				uid:0,
			};
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
		
				this.page++;
				this.getList();
		
		},
		onShow() {
			let _this = this;
			
			if(uni.getStorageSync('lang')){
				this.lang =  uni.getStorageSync('lang');
			}
			
			this.uid = uni.getStorageSync("userinfo").id;
			
			
			if(this.lang == 1){
				uni.setNavigationBarTitle({
						 title: 'People in the vicinity'
				})
			}else{
				uni.setNavigationBarTitle({
					   title: '附近的人'
				})
			}
		},
		methods: {
			shanchu(id,index,indexs){
				
				
				let _this = this;
				this.$api.request('/api/user/liuyandel', {
					id:id,
				}, this.$store.state.token, function(res){
				
						let ss = _this.list[indexs].list;
						console.log(ss,97979792)	
						ss.splice(index,1);
						
						if(_this.lang==0){
							uni.showToast({
								title: '操作成功',
								icon:"none"
							})
						}else{
							uni.showToast({
								title: 'Operation successful',
								icon:"none"
							})
						}
				
				});
			},
			 preview(url) {
				this.imgs = [url] //设置图片数组
		
				this.$nextTick(()=>{
					 this.$refs.previewImage.open(url); // 传入当前选中的图片地址(小程序必须添加$nextTick，解决组件首次加载无图)
				})
			
			},
			onLongpress(e){ //长按事件
				console.log('当前长按的图片是' + e);
				uni.showActionSheet({
					itemList: ['转发给朋友', '保存到手机'],
					success: function (res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
	
			/* open和close方法一般用不到，但是在一些特殊场景会用到，
			 * 比如预览图片时你需要覆盖 NavigationBar和 TabBar，
			 * 或者在app中需要预览图片时覆盖住原生组件，比如video或者map等，
			 * 你可以根据open和close去做一些操作，例如隐藏导航栏或者隐藏一些原生组件等
			 */
			open(){ //监听组件显示 （隐藏TabBar和NavigationBar，隐藏video原生组件）
				// uni.hideTabBar()
				// uni.setNavigationBarColor({
				//   frontColor: '#000000', // 设置前景色为黑色
				//   backgroundColor: '#000000', // 设置背景色为黑色
				// })
				// this.videoShow = false 
			},
			close(){ //监听组件隐藏 （显示TabBar和NavigationBar，显示video原生组件）
				// uni.showTabBar()
				// uni.setNavigationBarColor({
				//   frontColor: '#ffffff', // 设置前景色为白色
				//   backgroundColor: '#000000', // 设置背景色为黑色
				// })
				// this.videoShow = true
			},
			ck(item){
				if(this.show_id==item.id){
					this.show_id=0
				}else{
					this.show_id=item.id
				}
			},
			goDetail(url) {
				console.log(88888888888,url)
				
				uni.navigateTo({
					url: url
				})
				
			},
			miaoshu(){
				//留言内容必填
				if(this.dev_name.length<0 || this.dev_name == " " || this.dev_name == "   " 
				|| this.dev_name == "    " || this.dev_name == "    " || this.dev_name == "     "
				
				|| this.dev_name == "         " || this.dev_name == "       " || this.dev_name == "      "
				){
					if(this.lang==0){
						uni.showToast({
							title: '请输入内容',
							icon:"none"
						})
					}else{
						uni.showToast({
							title: 'Please enter the content',
							icon:"none"
						})
					}
					return;
				}
				
				let _this = this;
				console.log(this.info.uid,this.dev_name);
				this.$api.request('/api/user/liuyan', {
					content:this.dev_name,
					img:this.img,
					id:this.info.uid
				}, this.$store.state.token, function(res){
					if(res.code == 1) {
						//更新数据
						let datas = res.data;
						
						let info = _this.info
							console.log(datas,77777700)
						console.log(_this.index,7777770)
						console.log(_this.list,7777771)
						console.log(_this.list[_this.index].list,77777772)
						let ss = _this.list[_this.index].list;
						
							ss = ss.concat(datas)
							console.log(ss,77777773)
						_this.list[_this.index].list = ss;
						console.log(_this.list,7777774)
						
						if(_this.lang==0){
							uni.showToast({
								title: '操作成功',
								icon:"none"
							})
						}else{
							uni.showToast({
								title: 'Operation successful',
								icon:"none"
							})
						}
					}
					_this.$refs.popup2.close();
					_this.dev_name = "";
				});
				
				
			},
			showActionSheet() {
					
					if(!uni.getStorageSync('token')){
						return;
					}
								
				let _this = this;
				uni.showActionSheet({
					itemList: ['从手机相机选择', '拍一张'],
					success: function(res) {
						if (res.tapIndex == 0) {
							uni.chooseImage({
								count: 1,
								sizeType: ['compressed'],
								sourceType: ['album'],
								success: function(res) {
									_this.$api.uploadFile(res.tempFilePaths[0], _this.$store
										.state.token,
										function(res2) {
											
											if (res2.code == 1) {
												_this.img = res2.data.fullurl;
											}
										});
								}
							});
						} else if (res.tapIndex == 1) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'],
								sourceType: ['camera'],
								success: function(res) {
									_this.$api.uploadFile(res.tempFilePaths[0], _this.$store
										.state.token,
										function(res2) {
											console.log(res2,8882)
											if (res2.code == 1) {
											
												_this.img = res2.data.fullurl;
											
											}
										});
								}
							});
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			liuyan(item,index){
					this.info = item;
					this.index = index
					this.dev_name = "";
					this.$refs.popup2.open();
			},
			getList() {
				let _this = this;
				this.$api.request('/api/user/fujin', {
					page: this.page
				}, this.$store.state.token, function(res){
					if(res.code == 1) {
						if(_this.page == 1) {
							_this.list = res.data.data;
						}else {
							_this.list = _this.list.concat(res.data.data);
						}
						_this.total = res.data.total_item_count;
						if(_this.list.length > 0) {
							_this.nodata = false;
						}else {
							_this.nodata = true;
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fujin{
		background: #111823;
		min-height: 100vh;
		float: left;
		width: 100%;
		
		.share-wrapper1{
			height: 300rpx;;
			width:500rpx;
			z-index:9991;
			border-radius: 16rpx 16rpx 0 0;
			background: #111823;
		    border-radius: 0.8em;
			font-size: 30rpx;
			.tp{
				width: 100%;
				text-align: center;
				color: #fff;
				padding-top: 30rpx;;
			}
			.nav_tex{
				margin-bottom: 30rpx;
				margin-top: 20rpx;
				width: 88%;
				margin-left: 6%;
				input{
					margin-top: 10rpx;
					padding: 5px;
					background: #2c3747;
					border-radius: 0.5em;
					height:50rpx;
					line-height: 50rpx
				}
				textarea{
					width: 100%;
					color: #fff;
					font-size: 24rpx;
					background: #293241;
					height: 160rpx;
					padding: 5px;
				}
			}
			
			.bom{
				float: left;
				margin-top: 20rpx;
				width: 94%;
				margin-left: 3%;
				.left{
					color: #fff;
					float: left;
				}
				.right{
					float: right;
					margin-right: 20rpx;
					color: #fff;
					width: 180rpx;
					text-align: center;
					height: 70rpx;
					line-height:70rpx;
		
				}
				
			}
			.bomt{
				// float: left;
				margin: 0 auto;
				margin-top: 20rpx;
				width: 90%;
				text-align: center;
				background: #5F83F4;
				border-radius: 0.2em;
				height: 70rpx;;
				line-height: 70rpx;;
				color: #fff;
				margin-bottom: 20rpx;
				margin-left: 5%;
			}
			
		}
		.rightimg_str1{
		
			width: 146rpx;;
			color:#fff;
			height: 40rpx;
			line-height: 40rpx;
			font-size: 22rpx;
				
			border-radius: 5em;
			text-align: center;
			font-weight: 500;
			margin-left: 80rpx;
			float: left;
			color: #fff;
			&:last-child{
				width: 146rpx;;
				color:#fff;
				height: 40rpx;
				line-height: 40rpx;
				font-size: 22rpx;
				border-radius: 5em;
				text-align: center;
				font-weight: 500;
				margin-left: 20rpx;
				float: left;
				color: #fff;
				// background: orange;
			}
		}
		.lists{
			padding-top:10rpx;
			padding-bottom: 20rpx;
			margin-top: 10px;;
			width: 100%;
			background: #293241;
			box-shadow: 0 0 10rpx 0 rgba(118, 156, 255, 0.3);
			float: left;
			.list{
				padding-top: 20rpx;
				width: 100%;;
				color:#7A818E;
				float: left;
				font-size: 30rpx;
				
				&:last-child{
					border-bottom: none;
				}
				.fa{
					font-weight: 500;
					margin-left:55rpx;
					float: left;
					color: #fff;
				
				}
				.icon{
					border-radius: 5em;
					margin-right: 16rpx;
					width: 68rpx;
					height: 68rpx;
					float: left;
				}
				.rightimg_str{
					color:#fff;
					float:right;
					margin-right: 20px
				}
			}
		}
		
		
	}

	
</style>
